<style lang="sass" scoped>
    .img{
        width:120px;
    }
</style>
<template>
    <div  class="container">
        <div class="search-cont">
            <el-input placeholder="请搜索" v-model.trim="search.keyWord">
                <i slot="prefix" class="el-input__icon el-icon-search"></i>
            </el-input>
            <el-button @click="getList()" type="primary" :plain="false">搜索</el-button>
            <el-button @click="routerGo('device_add')" type="primary" :plain="false">新增</el-button>
        </div>
        <div class="table-cont">
            <el-table :data="list" style="width: 100%">
                <el-table-column prop="device" label="设备型号">
                </el-table-column>
                <el-table-column width="300px" prop="gzhUrl" label="公众号链接">
                </el-table-column>
                <el-table-column prop="createTime" label="创建时间">
                </el-table-column>
                <el-table-column width="260" label="操作">
                    <template slot-scope="props">
                        <el-button @click="routerGo('device_add',{id:props.row.id})" type="primary" :plain="false" size="small">修改</el-button>
                        <el-button @click="del(props.row)" type="primary" :plain="false" size="small">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination 
                background 
                layout="total, prev, pager, next"
                 :total="search.total" 
                 :page-size="search.pageSize"
                 @current-change="handleCurrentChange">
            </el-pagination>
        </div>
    </div>
</template>
<script>
    export default {
        components: {
        },
        data() {
            return {
                //列表搜索参数
                search:{
                    keyWord:'',//	是	string	搜索关键字
                    pageNo:1, //	是	string	页码
                    pageSize:config.pageSize, //	是	string	当前页显示的条数
                    total:0,
                },
                list:[],
            };
        },
        watch:{
            'search.isFree'(val){
                this.getList();
            }
        },
        created(){
        },
        mounted() {
            this.$nextTick(() => {
                this.getList();
            });
        },
        methods: {
            handleCurrentChange(val) {
                this.search.pageNo = val;
                this.getList();
            },
            getList() {
                let param = JSON.parse(JSON.stringify(this.search));
                util.ajax({
                    url: config.baseApi + "bookMall-admin/api/network/getDeviceNetworkListPage",
                    data: param,
                    success: data => {
                        this.list = data.data.record;
                        this.search.total = data.data.totalNum;
                    }
                });
            },
            del(item){
                popup.confirm({
                    content:'是否删除该设备联网？',
                    yes:()=>{
                        util.ajax({
                            url:config.baseApi + 'bookMall-admin/api/network/deleteDeviceNetwork',
                            data:{
                                id:item.id
                            },
                            success:(data=>{
                                popup.miss({content:'删除成功！'});
                                this.getList();
                            })
                        })
                    }
                })
            }
        },
        
    };
</script>